package com.yulan.bankback.mapper.bank;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yulan.bankback.entity.dto.bank.LoginDateDto;
import com.yulan.bankback.entity.dto.bank.LoginPlaceDto;
import com.yulan.bankback.entity.dto.bank.LoginTypeDto;
import com.yulan.bankback.entity.event.LoginEvent;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public interface LoginEventMapper extends BaseMapper<LoginEvent> {

    @Select("select login_date as date, count(1) as count from user_login_event where " +
            "uid = #{uid} and  login_date > NOW() - INTERVAL  ${interval} group by login_date")
    List<LoginDateDto> getGroupLoginDateInterval(@Param("uid") String uid,
                                                 @Param("interval") String interval);

    @Select("select login_type as type, count(1) as count from user_login_event where " +
            "uid = #{uid} and  login_date > NOW() - INTERVAL  ${interval} group by login_type")
    List<LoginTypeDto> getGroupLoginTypeInterval(@Param("uid") String uid,
                                                 @Param("interval") String interval);


    @Select("select login_place as place, count(1) as count from user_login_event where " +
            "uid = #{uid} and  login_date > NOW() - INTERVAL  ${interval} group by login_place")
    List<LoginPlaceDto> getGroupLoginPlaceInterval(@Param("uid") String uid,
                                                   @Param("interval") String interval);

    @Select("select uid, login_place, login_date, login_type from user_login_event " +
            "where uid = #{uid} and login_date > NOW() - INTERVAL 1 month")
    List<LoginEvent> getLastMonthEvent(@Param("uid") String uid);



}
